package com.jy.wms.controller;

import com.jy.wms.common.SetStatus;
import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.common.base.ReturnType;
import com.jy.wms.common.base.SetAndModifyModel;
import com.jy.wms.pojo.WmsQcEnclosure;
import com.jy.wms.service.WmsQcEnclosureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: WmsQcEnclosureController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Tue Dec 19 18:06:19 CST 2017
 */
@Controller
@RequestMapping("/wmsqcenclosure")
@Api(value = "/wmsqcenclosure", description = "关于质检单附件操作")
public class  WmsQcEnclosureController extends BaseController<WmsQcEnclosureService,WmsQcEnclosure> {

    @ApiOperation(value = "关于质检单附件操作 质检单附件列表", response = JSONObject.class, notes = "查询质检单附件列表")
    @PostMapping(value = "/list/{sszjdid}")
    public @ResponseBody JSONArray getWmsQcEnclosure(@PathVariable("sszjdid") String sszjdid, HttpSession session) {
        List<WmsQcEnclosure> list = new ArrayList<WmsQcEnclosure>();
        JSONArray json = new JSONArray();
        try {
            json = JSONArray.fromObject( baseService.baseSelectPage(sszjdid));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "关于质检单附件操作 批量删除质检单附件",response = JSONObject.class, notes = "批量删除质检单附件")
    public @ResponseBody JSONObject deleteWmsQcEnclosure(@RequestBody SetAndModifyModel setAndModifyModel) {
        try{
            Integer flag=baseService.baseDeleteBathPrimaryKeys(setAndModifyModel.getIds());
            if(flag>0){
                return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"批量删除质检单附件成功","", "");
            }else{
                return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.error.toString(),"批量删除质检单附件失败","", "");
            }
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"批量删除质检单附件失败",e.getMessage(),"");
        }
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "关于质检单附件操作 新增质检单附件",response = JSONObject.class, notes = "新增质检单附件")
    public @ResponseBody JSONObject addWmsQcEnclosure(@RequestBody WmsQcEnclosure entity) {
        try{
            entity.setId(UUIDUtils.uuid());
            baseService.baseInsert(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"新增质检单附件成功","", "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"新增质检单附件失败",e.getMessage(),"");
        }
    }

    @GetMapping(value = "getWmsQcEnclosure/{id}")
    @ApiOperation(value = "查看单个信息",response = JSONObject.class, notes = "GET查看单个信息")
    public @ResponseBody
    WmsQcEnclosure getWmsQcEnclosureById(@PathVariable("id") String id) {
        WmsQcEnclosure entity=baseService.baseSelectByPrimaryKey(id);
        return entity;
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "关于质检单附件操作 编辑质检单附件",response = JSONObject.class, notes = "编辑质检单附件")
    public @ResponseBody JSONObject editWmsQcEnclosure(@RequestBody WmsQcEnclosure entity) {
        try{
            baseService.baseUpdateByPrimaryKeySelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"编辑质检单附件成功","", "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.error.toString(),"编辑质检单附件失败",e.getMessage(), "");
        }
}
}
